import java.nio.file.Files;

public class Day29 {
    public static int getFirstUnFormedNum(int[] arr) {

        int min = Integer.MAX_VALUE;
        int max = 0;
        for (int i = 0; i < arr.length; i++) {
            max += arr[i];
            min = Math.min(min, arr[i]);
        }
        int[] dp = new int[max+1];
        for (int i = 0; i < arr.length; i ++) {
            for (int j = max; j >= min; j --) {
                if (j >= arr[i]) {
                    dp[j] = Math.max(dp[j],dp[j-arr[i]] + arr[i]);
                }
            }
        }
        // 找结果，如果 dp[j] != j 说明不存在和
        for (int j = min; j <= max; j ++) {
            if (dp[j] != j) {
                return j;
            }
        }
        return max + 1;
    }

    public static void main(String[] args) {
        int[] arr = {2,3,5};
        int firstUnFormedNum = getFirstUnFormedNum(arr);
        System.out.println(firstUnFormedNum);
    }
}
